﻿Imports Mystery

''' <summary>
''' a mapper which help in converting content in db formats
''' </summary>
''' <remarks></remarks>
<GlobalAvalibleObjectImplementation(singleton:=True)>
Public Class PropertyControlDefaults

    Private Property ContentPropertyControls As IDictionary(Of Type, Type)
    Private Property ReadOnlyPropertyControls As IDictionary(Of Type, Type)

    Public Sub New()
        ContentPropertyControls = New Dictionary(Of Type, Type)
        ContentPropertyControls(GetType(String)) = GetType(StringView)
        ContentPropertyControls(GetType(Double)) = GetType(DoubleView)
        ContentPropertyControls(GetType(Integer)) = GetType(IntegerView)
        ContentPropertyControls(GetType(Date)) = GetType(DateView)
        ContentPropertyControls(GetType(Boolean)) = GetType(BooleanView)

        ReadOnlyPropertyControls = New Dictionary(Of Type, Type)
        ReadOnlyPropertyControls(GetType(String)) = GetType(ReadOnlyString)
        ReadOnlyPropertyControls(GetType(Double)) = GetType(ReadOnlyDouble)
        ReadOnlyPropertyControls(GetType(Integer)) = GetType(ReadOnlyInteger)
        ReadOnlyPropertyControls(GetType(Date)) = GetType(ReadOnlyDateView)
        ReadOnlyPropertyControls(GetType(Boolean)) = GetType(ReadOnlyBoolean)

    End Sub

    Public Function getDefaultViewFor(type As Type) As Type
        If ContentPropertyControls.ContainsKey(type) Then
            Return ContentPropertyControls(type)
        End If
        Try
            type.GetInterfaceMap(GetType(IContent))
            Return GetType(ReadOnlyReference)
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

    Public Function getReadViewFor(type As Type) As Type
        If ReadOnlyPropertyControls.ContainsKey(type) Then
            Return ReadOnlyPropertyControls(type)
        End If
        Try
            type.GetInterfaceMap(GetType(IContent))
            Return GetType(ReadOnlyReference)
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

End Class

